﻿using FluentMigrator;
using FluentMigrator.Builders.Create.Table;

namespace Rubikev.Rockface.Database.Tables
{
   /// <summary>
   /// Creates the Point table
   /// </summary>
   [Migration(201106051910)]
   public class CreatePointTable : CreateTableMigration
   {
      /// <summary>
      /// The name of the route ID column
      /// </summary>
      private const string RouteIdColumnName = "RouteId";

      /// <summary>
      /// The name of the point table
      /// </summary>
      public override string TableName
      {
         get { return "Point"; }
      }

      /// <summary>
      /// Creates the Id, X, Y and Index columns
      /// </summary>
      /// <param name="table">The point table</param>
      protected override void CreateColumns(ICreateTableWithColumnOrSchemaSyntax table)
      {
         table
            .WithColumn("Id").AsInt32().PrimaryKey()
            .WithColumn("X").AsDouble()
            .WithColumn("Y").AsDouble()
            .WithColumn("[Index]").AsInt32()
            .WithColumn(RouteIdColumnName).AsInt32();
      }

      /// <summary>
      /// Creates an index on the route ID column
      /// </summary>
      protected override void CreateIndexes()
      {
         base.CreateIndexes();
         CreateIndex(RouteIdColumnName);
      }
   }
}
